<template>
	<view class="container">
		<view>
			<div class="tx">
				<image src='../../static/head_icon.png'></image>
			</div>
		</view>
		<div class="tianbiao">
			<uni-forms ref="form" :rules="{}">
				<uni-forms-item label="用户名：" name="">
					<uni-easyinput v-model="user.name" placeholder="请输入用户名" />
				</uni-forms-item>
				<uni-forms-item label="密码：" name="">
					<uni-easyinput v-model="user.password" placeholder="请输入密码" type="password" />
				</uni-forms-item>
			</uni-forms>
		</div>
		<view>
			<uni-forms-item label="" name="">
				<button type="primary" @click="login">登录</button>
			</uni-forms-item>
			<uni-forms-item label="" name="">
				<button>注册</button>
			</uni-forms-item>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user: {
					name: '',
					password: ''
				}
			}
		},
		methods: {
			login(e) {
				uni.request({
					url: 'http://localhost:8090/freshmenapp/user/login',
					method: 'POST',
					data: this.user,
					success: res => {
						console.log(res.data);
						if (res.data.success) {
							uni.showToast({
								title: '' + res.data.data.name,
							});
							uni.setStorageSync("list", res.data.data)
							uni.switchTab({
								url: '/pages/my/my'
							})
						} else {
							uni.showToast({
								title: '用户名或密码不正确',
								icon: 'none'
							});
						}
					},
					fail: () => {
						uni.showToast({
							title: '登录失败',
							icon: 'none'
						});
					},
					complete: () => {}
				});

			}
		}
	}
</script>

<style>
	view {
		margin: 10px 0 0 0;
	}

	image {
		width: 120px;
		height: 120px;
		/* display: grid; */
		justify-content: center;
		/* align-items: center; */
		/* text-align: center; */
		border-radius: 25%;
	}

	.tx {
		text-align: center;
		margin: 50px 0 0 0;
	}

	.tianbiao {
		margin: 0 0 0 10px;
	}

	uni-easyinput {
		width: 100vw;
	}

	button {
		width: 100vw;
	}
</style>